// 由于 laravel 本来就已经封装好了 css 和 js 的压缩了，所以我就不再重复了
var elixir = require('laravel-elixir'),
    gulp = require('gulp'),
    imagemin = require('gulp-imagemin'),
    autoprefixer =  require('gulp-autoprefixer');
/*
 |--------------------------------------------------------------------------
 | Elixir Asset Management
 |--------------------------------------------------------------------------
 |
 | Elixir provides a clean, fluent API for defining some basic Gulp tasks
 | for your Laravel application. By default, we are compiling the Sass
 | file for our application, as well as publishing vendor resources.
 |
 */
// 压缩 图片
gulp.task('imageMin', function () {
    gulp.src('./public/images/original/*.{png,jpg,gif,ico}')
        .pipe(imagemin({
                optimizationLevel: 5, //类型：Number  默认：3  取值范围：0-7（优化等级）
                progressive: true, //类型：Boolean 默认：false 无损压缩jpg图片
                interlaced: true, //类型：Boolean 默认：false 隔行扫描gif进行渲染
                multipass: true //类型：Boolean 默认：false 多次优化svg直到完全优化
        }))
        .pipe(gulp.dest('./public/images/compress'));
});

// 添加 css 私有前缀
gulp.task('autoprefixer', function () {
    gulp.src('./public/css/*.css')
        .pipe(autoprefixer({
            browsers: ['last 2 versions', 'Android >= 4.0','> 5%'],
            cascade: true, //是否美化属性值 默认：true 像这样：
            remove:true //是否去掉不必要的前缀 默认：true
        }))
        .pipe(gulp.dest('./public/css'));
});

elixir(function(mix) {
    mix.sass('admin/admin.scss');
    mix.task('autoprefixer');
    mix.task('imageMin');
    mix.version('css/admin.css');
});
